package com.sq.partner.manager.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.xml.resolver.apps.resolver;
import org.springframework.stereotype.Repository;

import com.sq.partner.manager.dao.TradeFeeCovDao;
import com.sq.partner.manager.mybatis.model.NlifeCov;
import com.sq.partner.manager.mybatis.model.TradeFeeCov;
import com.sq.partner.manager.util.LogUtil;
@Repository
public class TradeFeeCovDaoImpl extends BaseDaoImpl implements TradeFeeCovDao {
	private static Logger logger = LogUtil.getLog(TradeFeeCovDaoImpl.class);
	@Override
	public Integer getMaxId() {
		Integer result = this.getSession().selectOne("selectMaxFeeCoVId");
		return result;
	}
	@Override
	public List<TradeFeeCov> getTradeFeeCov(Map<String, Object> map) throws SQLException {
		return this.queryList("selecttradeByCondition", map);
	}
	@Override
	public boolean deleteTradeCov(Map<String, Object> map) throws Exception {
		return this.delete("deletetradeFeeCovbycondition", map);
	}
	@Override
	public boolean addTradeCov(Map<String, Object> map) throws Exception {
		return this.add("inserttradeFeeCovNewLife", map);
	}
	@Override
	public Integer checkInsure(String prodCode) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		int count=0;
		try {
			conn = this.getConnection();
			String sql="select  count(nvl(t.product_code,0)) from t_gateway_policy t join T_NLIFE_PLAN p  on t.product_code=p.plan_no join T_NLIFE_PROD n on n.prod_code=p.prod_code  where p.prod_code=? and  t.state_id='2'";
			pstmt=conn.prepareStatement(sql);
			pstmt.setString(1, prodCode);
			ResultSet result=pstmt.executeQuery();
			if(result.next()){
				count=result.getInt(1);
			}
		} catch (SQLException e) {
			logger.error(e);
		}finally{
			try {
				pstmt.close();
				conn.close();
			} catch (SQLException e) {
				logger.error(e);
			}
		}
		return count;
	}
	@Override
	public boolean deleteTradeCov1(Map<String, Object> map) throws Exception {
		return this.delete("deletetradeFeeCovbycondition1", map);
	}
	@Override
	public String getRemark(String calDefIdAll) throws SQLException {

		return (String) this.query("selectCallRemark", calDefIdAll);
	}
	@Override
	public List<Map<String, Object>> impNlifeCall(Map<String, Object> map)
			throws SQLException {
		return this.queryList("impNlifeCallByMap", map);
	}
}
